<template>
  <template v-if="user">
    <van-cell title="当前用户" :value="user?.username" style="font-size: 20px; padding-top: 20px"/>
    <van-cell title="详细用户信息" is-link to="/user/update" style="font-size: 16px; padding-top: 20px">
      <img src="../assets/zl03.jpg"/>
    </van-cell>
    <van-cell title="我创建的队伍" is-link to="/user/team/create" style="font-size: 16px; padding-top: 20px" >
      <img src="../assets/zl02.jpg"/>
    </van-cell>
    <van-cell title="我加入的队伍" is-link to="/user/team/join" style="font-size: 16px; padding-top: 20px" >
      <img src="../assets/zl01.jpg"/>
    </van-cell>
  </template>
  <div style="padding-top: 20px">
    <van-button type="primary" to="/user/login" block @click="logout()">退出登录</van-button>
  </div>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user";
import myAxios from "../plugins/myAxios";
import { Toast } from "vant";

const user = ref();

const router = useRouter();

onMounted(async () => {
  user.value = await getCurrentUser();
})

const toEdit = (editKey: string, editName: string, currentValue: string) => {
  router.push({
    path: '/user/edit',
    query: {
      editKey,
      editName,
      currentValue,
    }
  })
}

const logout = async () => {
  const res = await myAxios.post('/user/logout',{});
  console.log("退出", res.code)
  if (res?.code === 0) {
    Toast('退出成功');
    router.replace('/user/login') //重定向到登录页
  }
}
</script>


<style scoped>
img {
  width: 25px;
  height: 25px;
}
</style>
